﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AppPort;
using TiEntityObject.Notification;
using TiPort.TiEntityObjects;
using System.Web;
using TI_EntityLib.TiEntityObjects.Kladr;

namespace Controllers.AdministrationControllerCommands
{
    /// <summary>
    /// Вернуть строки документов
    /// </summary>
    public class GetDrugItems
    {
        private class inGetDrugItems
        {
            public string root { get; set; }
            public string ContentInfo { get; set; }
            //public bool OnlyStage1 { get; set; }
        }

        private class outGetDrugItems 
        {
            public string ID { get; set; }
            public string Path { get; set; }
            public string NodeType { get; set; }
            public string NameR { get; set; }
            public string NameE { get; set; }            

            public string id { get {return ID;} }
            public bool leaf { get { return (NodeType != "PhGr"); } }
            public string text { get { return NameR; } }
            public bool @checked { get; set; }  
        }

        public static string Run(ServiceCmd cmd)
        {
            string node ="root";            
            node = HttpContext.Current.Request["node"];
            if(node.Equals ("root"))
                return "{success:true, d:[{id:null, text: 'Справочник ЛС'}]}";          
            var script = "getDrugTree('"+(node==""?"root":node)+ "')";
            List<outGetDrugItems> lst = Helper.MongoTools.Instance.GetCollection<outGetDrugItems>(script);
            string s = Helper.Json<outGetDrugItems>.ListToJson(lst);
            return "{success:true, d:"+s+"}";            
        }
    }
}
